package ezXpns.storage.queries;

import org.apache.lucene.search.NumericRangeQuery;

import ezXpns.BudgetChange;
import ezXpns.storage.Query;


//@author A0088827L
public class AmountRangeQuery implements Query<BudgetChange> {
	
	public AmountRangeQuery(float from, float to) {
		this.from = from;
		this.to = to;
		this.luceneQuery = 
			NumericRangeQuery.newFloatRange(
				"amount",
				from,
				to,
				true,
				true
			);
	}

	@Override
	public boolean apply(BudgetChange arg) {
		float amount = arg.getAmount();
		return from <= amount && amount <= to;
	}

	@Override
	public org.apache.lucene.search.Query asLuceneQuery() {
		return luceneQuery;
	}
	
	private float from;
	private float to;
	private NumericRangeQuery<Float> luceneQuery;
}
